<?php

namespace YmPhp\Admin\Http\Controllers\Business;

use YmPhp\Admin\Http\Repositories\Business\BusinessNotice;
use YmPhp\Admin\Form;
use YmPhp\Admin\Grid;
use YmPhp\Admin\Models\Business\BusinessList;
use YmPhp\Admin\Show;
use YmPhp\Admin\Http\Controllers\AdminController;

class BusinessNoticeController extends AdminController
{
    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(new BusinessNotice(), function (Grid $grid) {
            $grid->model()->orderBy('id', 'desc');
            $grid->column('id')->sortable();
            $grid->column('shid')->width(200)->display(function ($value) {

                $business = (new BusinessList())->getDetails($value);
                $businessInfo = "商家名称：{$business->name}<br>";
                $businessInfo .= "联系电话：{$business->tel}<br>";
                return $businessInfo;
            });
            $grid->column('content')->limit(120);
            $grid->column('created_at')->width(100);
            $grid->column('updated_at')->width(100)->sortable();
            $grid->disableViewButton();
            $grid->disableCreateButton();
            $grid->disableEditButton();

            $grid->filter(function (Grid\Filter $filter) {
                $filter->equal('id');

            });
        });
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     *
     * @return Show
     */
    protected function detail($id)
    {
        return Show::make($id, new BusinessNotice(), function (Show $show) {
            $show->field('id');
            $show->field('shid');
            $show->field('content');
            $show->field('created_at');
            $show->field('updated_at');
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(new BusinessNotice(), function (Form $form) {
            $form->display('id');
            $form->text('shid');
            $form->text('content');

            $form->display('created_at');
            $form->display('updated_at');
        });
    }
}
